package com.shelpe.services.scheduler.item.customer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ItemProcessListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shelpe.services.scheduler.po.SyncLog;
import com.shelpe.services.scheduler.po.Users;
import com.shelpe.services.scheduler.repository.SyncLogRepository;

@Component("userProcessListener")
public class UserProcessListener implements ItemProcessListener<Users, SyncLog>{

	private static final Logger logger = LoggerFactory.getLogger(UserProcessListener.class);
	
	@Autowired
	private SyncLogRepository syncRep;
	
	@Override
	public void beforeProcess(Users item) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void afterProcess(Users item, SyncLog result) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProcessError(Users item, Exception e) {
		// TODO Auto-generated method stub
		SyncLog log = new SyncLog();
		log.setUserId(item.getUserId());
		log.setNick(item.getNick());
		log.setMessage("Failed");
		logger.info("UserProcessListener userId {} failed", item.getUserId());
		logger.info(" detail error info: {}", e);
		syncRep.save(log);
	}

}
